package br.usp.wta.aux;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static javax.swing.JOptionPane.*;

import br.usp.language.morph.AnalisadorMorfologico;
import br.usp.language.morph.MorphologicAnalyser;
import br.usp.language.morph.PortugueseAnalyser;
import br.usp.language.morph.TokenMorph;

public class TextMorphs2 {
    
    private static final String DICFILE = "resources/port";
    private static final String LISTFILE = "resources/port_amor_config.list";
    private static final String NEWSIN = "resources/training/news_in.txt";
    private static final String NARIZINHO = "resources/training/narizinho.txt";
    private static final String PONCT = " (.*?)([;,.])";
    
    public static void main(String[] args) throws IOException {
        
        MorphologicAnalyser ma = new AnalisadorMorfologico(DICFILE);

        File out = new File(NARIZINHO);
        Reader reader = new FileReader(out);        
        ma.setInput(reader);
        
        List<TokenMorph> tokens = new ArrayList<TokenMorph>();
        while (ma.hasMoreTokens()) {
            TokenMorph[] tks = ma.getNextTokens();
            if ((tks != null) && (tks.length > 0)) {
                if (tks[0].getLexeme().matches("\\.;\\?!")) {
                    System.out.println();
                } else {
                    String palavra = tks[0].getLexeme();
                    Set<String> options = new HashSet<String>();
                    for (TokenMorph tk : tks) {
                        options.add(tk.getType());
                    }
                    String[] selectionValues = options.toArray(new String[0]);
                    
                    String resp;
                    if (tks.length > 1) { 
                        resp = (String) showInputDialog(null, palavra, "Classifique", QUESTION_MESSAGE, null, selectionValues, selectionValues[0]);
                    }
                    else {
                        resp = tks[0].getType();
                    }

                    System.out.print(palavra + "(" + resp + ") ");
                }
            }
            else {
                System.out.print("_____(null) ");
            }
        }
        
        
        reader.close();
    }

}
